package cn.rubintry.bug.hunting.banner

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import cn.rubintry.bug.hunting.pojo.HomeBackgroundModel
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter


class ImageAdapter(private val mData: MutableList<HomeBackgroundModel>) : BannerAdapter<HomeBackgroundModel , ImageAdapter.BannerViewHolder>(mData) {

    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent?.context)
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP;
        return BannerViewHolder(imageView);
    }


    override fun onBindView(
        holder: BannerViewHolder,
        data: HomeBackgroundModel,
        position: Int,
        size: Int
    ) {
        Glide.with(holder.imageView.context)
            .load(data.url)
            .into(holder.imageView)
    }


}